﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen axisPen = new Pen(Color.Black);
            Pen gridPen = new Pen(Color.LightGray);
            Brush textBrush = Brushes.Black;
            Font textFont = new Font("Arial", 8);

            // 获取Panel的宽度和高度
            int panelWidth = panel1.Width/2;
            int panelHeight = panel1.Height;
            int FG = panel1.Left;
            int PX = panel1.Left+2;
            int PY= panel1.Bottom - 40;

            // 定义自定义坐标系的范围
            int customMinX = 30;
            int customMaxX = 360;
            int customMinY = 0;
            int customMaxY = 255;

            // 绘制X轴和Y轴
            g.DrawLine(axisPen, PX, PY, PX+ panelWidth, PY); // X轴
            //g.DrawLine(axisPen, PX, panelHeight, PX, 0); // Y轴

            // 绘制X轴刻度
            for (int i = 0; i <= 10; i++)
            {
                int x = (int)((double)i / 10 * panelWidth)+40; // 减1是为了避免超出Panel边界
                int customX = customMinX + (int)((double)i / 10 * (customMaxX - customMinX));
                g.DrawLine(gridPen, x, panelHeight, x , panelHeight - 6); // 减6是为了让刻度线短一点
                g.DrawString(customX.ToString(), textFont, textBrush, x + 13, panelHeight);
            }

            //// 绘制Y轴刻度
            //for (int i = 0; i <= 10; i++)
            //{
            //    int y = panelHeight - (int)((double)i / 10 * (panelHeight - 20)); // 减1是为了避免超出Panel边界
            //    int customY = customMinY + (int)((double)i / 10 * (customMaxY - customMinY));
            //    g.DrawLine(gridPen, 20, y, 25, y);
            //    g.DrawString(customY.ToString(), textFont, textBrush, 20, y - 7);
            //}





        }
    }
}
